﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StringDefs.SourceCode
{
    using StringDefs.Common;
    public static class SourceCode
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="codeLine"></param>
        /// <returns></returns>
        public static string MakeCComment(this string codeLine)
        {
            return "/*" + codeLine + "*/";
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="codeLine"></param>
        /// <returns></returns>
        public static bool isJavaComment(this string codeLine)
        {
            //because CPP and java uses the same commenting style
            return isCPPComment(codeLine);
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="codeLine"></param>
        /// <returns></returns>
        public static bool IsCComment(this string codeLine)
        {

            bool status = false;
            codeLine = codeLine.Trim();
            if (codeLine.StartsWith("/*") && codeLine.EndsWith("*/"))
                status = true;
            return status;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="codeLine"></param>
        /// <returns></returns>
        public static bool isCPPComment(this string codeLine)
        {
            bool status = false;
            codeLine = codeLine.Trim();
            if (codeLine.StartsWith("//"))
                status = true;
            return status;

        }

        /// <summary>
        /// This returns true if the specified argument codeLine is a valid VB comment
        /// </summary>
        /// <param name="codeLine">The suspicious code line</param>
        /// <returns>Boolean</returns>
        public static bool isVBComment(this string codeLine)
        {
            bool status = false;
            codeLine = codeLine.Trim();
            if (codeLine.StartsWith("'"))
                status = true;
            return status;
        }

        /// <summary>
        /// Returns true if the argument is a valid name for a C,C++,Java,C# or VB.NET identifier.
        /// </summary>
        /// <param name="identifier"></param>
        /// <returns></returns>
        public static bool IsValidIdentifier(this string identifier)
        {
            bool status = false;
            char[] symbols = {'`','~','!','@','#','$','%','^','&','*','(',')'
                ,'-','=','+','{','}','[',']','|','\\',':',';','"','\'','<','>',',','.','?','/'};

            if (identifier.StartsWithAlphabets() || identifier.StartsWith("_"))
            {
                if (identifier.ContainsAnyOf(symbols))
                {
                    status = false;
                }
                else
                {
                    status = true;
                }
            }

            return status;
        }     
    }
}
